﻿using System.Windows;

namespace WinSource.Controls
{
    public partial class TitleControl
    {
        #region Fields

        public static readonly DependencyProperty TitleNameProperty = DependencyProperty.Register("TitleName", typeof(string), typeof(TitleControl),
                                                                                                  new PropertyMetadata(OnRegisterProperty));

        public static readonly DependencyProperty PageNameProperty = DependencyProperty.Register("PageName", typeof(string), typeof(TitleControl),
                                                                                                 new PropertyMetadata(OnRegisterProperty));

        #endregion

        #region Constructors

        public TitleControl()
        {
            InitializeComponent();
        }

        #endregion

        #region Properties

        public string TitleName
        {
            get { return (string)GetValue(TitleNameProperty); }
            set { SetValue(TitleNameProperty, value); }
        }

        public string PageName
        {
            get { return (string)GetValue(PageNameProperty); }
            set { SetValue(PageNameProperty, value); }
        }

        #endregion

        #region Private Methods

        private static void OnRegisterProperty(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
        {
            TitleControl titleControl = dependencyObject as TitleControl;

            if (titleControl != null)
            {
                titleControl.Update();
            }
        }

        private void Update()
        {
            TextBlockTitle.Text = TitleName;
            TextBlockPage.Text = PageName;
        }

        #endregion
    }
}